<?php
/**
 * 【通讯录】接口控制器
 * 
 */
class contactsAction extends apiAction {
	
	/**
	 * 获得联系人列表
	 */
	public function index(){
		$departmentId = I('departmentId');
		$page	= I('page', 1);	// 要显示第几页数据
		$num	= I('num', 20);	// 每页显示多少条数据
		
		$where['roleId'] = 7;
		$where['status'] = 1;
		if($departmentId){
			$where['storeId'] = $departmentId;
		}
		
		$data = D('admin')->alias('u')->field('u.realName AS name, u.phone, u.email, u.jobPost, s.name AS department')
				->join(C('DB_PREFIX')."store AS s ON s.id = u.storeId")
				->where($where)
				->limit($num)->page($page)->select();
		
		$this->ajaxReturn(200, L('success'), $data);
	}
	
	/**
	 * 城市列表
	 */
	public function city(){
		$data= D('region')->field('id,name')->where(array('level'=>1))->select();
		$this->ajaxReturn(200, L('success'), $data);
	}
	
	/**
	 * 获得部门列表
	 */
	public function department(){
		$cityId = I('cityId');
		
		$data = D('store')->alias('s')->field('s.id,s.name')
				->join(C('DB_PREFIX')."region AS r ON r.id = s.regionId")
				->join(C('DB_PREFIX')."region AS c ON c.id = r.pid")
				->where(array('c.id'=>$cityId))->select();
		$this->ajaxReturn(200, L('success'), $data);
	}

}
/* End of file contactsAction.class.php */